﻿﻿@using FCZLM.Core.Models
@{
    Layout = null;
    var list = ViewBag._productsRepository as List<Products>;
}
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Add</title>
    <link href="/layui/css/layui.css" rel="stylesheet" />
    

</head>
<body>
    <div>
        <div class="layui-card">
            <div class="layui-card-header">添加商品图片</div>
            <div class="layui-card-body">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片</label>
                        <div class="layui-input-block">
                            <input type="file" name="PicUrl1" id="uploadimg" />
                            <input type="hidden" name="PicUrl" id="url" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <img id="my_img" style="width:200px;height:200px" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="PicType" required lay-verify="required" placeholder="请输入类型" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品</label>
                        <div class="layui-input-block">
                            <select name="ProductId" lay-verify="required">
                                @foreach (var item in list)
                                {
                                    <option value="@item.Id">@item.Name</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="Addform">添加</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="/layui/layui.js"></script>
    <script>

        layui.use(["form", 'layer', 'upload'], function () {
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var upload = layui.upload;
            //处理图片上传
            upload.render({
                elem: "#uploadimg",//点击谁上传图片
                url: "/FProductUrls/uploadimg",//图片上传到哪里
                done: function (res) {
                    //上传成功之后的处理
                    if (res.code == 0) {
                        //显示图片
                        $("#my_img").attr("src", res.path);
                        //path存起来
                        $("#url").val(res.path);
                    }
                }
            })
            //提交
            form.on('submit(Addform)', function (data) {
                $.post("/fproducturls/add", data.field, function (res) {
                    if (res.isSuccess) {
                        layer.msg(res.msg, function () {
                            parent.window.location.href = "/fproducturls/index";
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                });
                return false;
            });
        })
    </script>
</body>
</html>

